package io.github.talelin.latticy.service.K;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.github.talelin.latticy.common.mybatis.Page;
import io.github.talelin.latticy.mapper.K.AcquisitioncardMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.talelin.latticy.model.K.AcquisitioncardDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generator@TaleLin
 * @since 2021-06-08
 */
@Service
public class AcquisitioncardService extends ServiceImpl<AcquisitioncardMapper, AcquisitioncardDO> {

    @Autowired
    private AcquisitioncardMapper AcquisitioncardMapper;

    public AcquisitioncardDO getById(Integer id) {
        AcquisitioncardDO b_gateway = AcquisitioncardMapper.selectById(id);
        return b_gateway;
    }

//    public List<AcquisitioncardDO> getAcquisitioncardByKeyword(String q) {
//        List<AcquisitioncardDO> Acquisitioncards = AcquisitioncardMapper.selectByNameLikeKeyword(q);
//        return Acquisitioncards;
//    }

//    public AcquisitioncardDetailDO getDetail(Long id){
//
//        return this.getBaseMapper().getDetail(id);
//    }

    public IPage<AcquisitioncardDO> seachAcquisitioncard(Page<AcquisitioncardDO> pager, String keyword, String StartTime, String EndTime,String dwmc,String bgateway_name,String collector_name, String collector_power, String tresult, String hresult,String dwmc1,
                                                 String bgateway_name1,
                                                 String collector_name1,
                                                 String dwmc2,
                                                 String bgateway_name2,
                                                 String collector_name2,
                                                 String dwmc3,
                                                 String bgateway_name3,
                                                 String collector_name3,
                                                 String dwmc4,
                                                 String bgateway_name4,
                                                 String collector_name4){
        QueryWrapper<AcquisitioncardDO> wrapper = new QueryWrapper<>();
        if(StartTime != ""){
            wrapper.ge("collector_time",StartTime);
        }
        if(EndTime != ""){
            wrapper.le("collector_time",EndTime);
        }
        if(collector_power != ""){
            wrapper.le("collector_power",collector_power);
        };
        if(tresult != ""){
            wrapper.eq("t_result",tresult);
        };
        if(hresult != ""){
            wrapper.eq("h_result",hresult);
        };
        if(dwmc != "") {
            wrapper.and(i -> i.eq("dwmc", dwmc)
                    .or().eq("dwmc", dwmc1)
                    .or().eq("dwmc", dwmc2)
                    .or().eq("dwmc", dwmc3)
                    .or().eq("dwmc", dwmc4));
        }
        if(bgateway_name != "") {
            wrapper.and(i -> i.eq("b_gateway_name", bgateway_name)
                    .or().eq("b_gateway_name", bgateway_name1)
                    .or().eq("b_gateway_name", bgateway_name2)
                    .or().eq("b_gateway_name", bgateway_name3)
                    .or().eq("b_gateway_name", bgateway_name4));
        }
        if(collector_name != "") {
            wrapper.and(i -> i.eq("collector_name", collector_name)
                    .or().eq("collector_name", collector_name1)
                    .or().eq("collector_name", collector_name2)
                    .or().eq("collector_name", collector_name3)
                    .or().eq("collector_name", collector_name4));
        }
        wrapper.and(i -> i.like("collector_name",keyword)
                .or().like("collector_power",keyword));
        IPage<AcquisitioncardDO> iPage = AcquisitioncardMapper.selectPage(pager,wrapper);
        return iPage;
    }
}
